package com.mt.channel.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.channel.entity.ChannelCoursePriceEntity;
import com.mt.channel.mapper.ChannelCoursePriceEntityMapper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;

@Component
public class ChannelCoursePriceServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ChannelCoursePriceServiceModel.class);

    @Autowired
    private ChannelCoursePriceEntityMapper channelCoursePriceEntityMapper;

    public ServiceResult<List<ChannelCoursePriceEntity>> selectList(Map<String, Object> params,
        PagerInfo<?> pagerInfo) {
        Assert.notNull(this.channelCoursePriceEntityMapper, "Property 'channelCoursePriceEntityMapper' is required.");
        ServiceResult<List<ChannelCoursePriceEntity>> result = new ServiceResult<List<ChannelCoursePriceEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }
            result.setResult(this.channelCoursePriceEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelCoursePriceServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<ChannelCoursePriceEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.channelCoursePriceEntityMapper, "Property 'channelCoursePriceEntityMapper' is required.");
        ServiceResult<ChannelCoursePriceEntity> result = new ServiceResult<ChannelCoursePriceEntity>();
        try {
            result.setResult(this.channelCoursePriceEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelCoursePriceServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(ChannelCoursePriceEntity channelCoursePriceEntity) {
        Assert.notNull(this.channelCoursePriceEntityMapper, "Property 'channelCoursePriceEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelCoursePriceEntityMapper.insert(channelCoursePriceEntity);
            if (save > 0) {
                id = channelCoursePriceEntity.getChannelCoursePriceId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelCoursePriceServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(ChannelCoursePriceEntity channelCoursePriceEntity) {
        Assert.notNull(this.channelCoursePriceEntityMapper, "Property 'channelCoursePriceEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelCoursePriceEntityMapper.updateByPrimaryKeySelective(channelCoursePriceEntity);
            if (save > 0) {
                id = channelCoursePriceEntity.getChannelCoursePriceId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelCoursePriceServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(ChannelCoursePriceEntity channelCoursePriceEntity) {
        Assert.notNull(this.channelCoursePriceEntityMapper, "Property 'channelCoursePriceEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelCoursePriceEntityMapper.updateByPrimaryKeySelective(channelCoursePriceEntity);
            if (save > 0) {
                id = channelCoursePriceEntity.getChannelCoursePriceId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelCoursePriceServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer channelCoursePriceId) {
        Assert.notNull(this.channelCoursePriceEntityMapper, "Property 'channelCoursePriceEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.channelCoursePriceEntityMapper.deleteByPrimaryKey(channelCoursePriceId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelCoursePriceServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }
}
